# -*- coding:utf-8 -*-
# Author:Ami
# @Time    : 2018/11/18 16:08
# 这是生成器
def fib(max):
    n, a, b = 0, 0, 1
    while n < max:
        yield (b) #想把什么返回出去就 yield 什么
        a, b = b, a + b
        n = n + 1
    return "done"


# adc = fib(10)
# print(adc.__next__())
# print("操作业务")
# print(adc.__next__())
# print(adc.__next__())
# print("操作业务")
#
# print(adc.__next__())
# print(adc.__next__())
#
# for i in adc:
#     print(i)

g = fib(6)

while True:
    try:
        x = next(g) #n内置方法  和__next__等同
        print('g:', x)
    except StopIteration as e:
        print('Generator return value', e.value)
        break
